package cn.wolfcode.wms.page;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

@Getter
@Setter
public class PageResult {

    private Integer currentPage;
    private Integer pageSize;
    private Integer totalCount;
    private Integer totalPage;
    private Integer nextPage;
    private Integer prevPage;
    private List<?> list;


    public PageResult(Integer pageSize, Integer totalCount, Integer currentPage, List<?> list) {
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.list = list;

        this.totalPage = totalCount % pageSize ==0 ? totalCount / pageSize : totalCount / pageSize +1;
        this.prevPage = currentPage - 1 > 0 ? currentPage -1 : currentPage;
        this.nextPage = currentPage + 1 > totalPage ? totalPage : currentPage+1;
    }

    public static PageResult empty(Integer pageSize){

        return new PageResult(pageSize, 0,1, Collections.emptyList());

    }

}
